package com.finger.hospservice.controller;

import com.finger.hospservice.service.HospitalService;
import com.finger.modelservice.model.hosp.Hospital;
import com.finger.modelservice.result.Result;
import com.finger.modelservice.vo.hosp.HospitalQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @PostMapping("findHospital/{page}/{limit}")
    public Result findHospital(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               @RequestBody(required = false) HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitals = hospitalService.findHospital(page==0?1:page,limit==0?10:limit,hospitalQueryVo);

        return Result.ok(hospitals);
    }

    @RequestMapping(value = "updateStatus/{id}/{status}",method = RequestMethod.PUT)
    public Result updateStatus(@PathVariable String id,
                               @PathVariable Integer status){
        hospitalService.updateStatus(id,status);

        return Result.ok();
    }

    @GetMapping("findHospital/{id}")
    public Result findHospital(@PathVariable String id){

        Map<String,Object> param = hospitalService.getById(id);

        return Result.ok(param);
    }

}
